<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/** @var \yii\web\View $this 当前视图 */
/** @var \builder\export\ExportBuilder $currentBuilder 当前组件 */
/** @var string $builderID 当前组件ID */
/** @var array $linker 下载链接 */
/** @var int $countLinker 下载链接数 */
/** @var int $totalCount 数据总条数 */
/** @var int $limit 每页数据条数 */

$currentBuilder = $this->context;
$countLinker = count($linker);
$totalCount = $currentBuilder->totalCount;
$limit = $currentBuilder->limit;
$builderID = $currentBuilder->id;
?>
<div id="__YM2_BUILDER_ID__<?= $builderID ?>" class="ui-custom-export card border-0 p-15" ng-controller="ym2.ctrl.<?= $builderID ?>">
    <!--页面开始-->
    <?= $currentBuilder->beginPage() ?>

    <!--头部工具-->
    <div class="card-body layui-border border-bottom-0 py-2 d-flex align-items-end justify-content-between">
        <div class="layui-form d-flex align-items-end">
            <input type="checkbox" name="<?= $builderID ?>DownloadSelector" layui-form-render lay-filter="ym2_form_checkbox" ng-true-value="1" ng-false-value="0" ng-model="checkboxAll">
            <text class="f13 text-secondary" ng-show="selectedCount > 0">已选 <text class="f14 text-dark">{{ selectedCount }}</text> 行</text>
        </div>
        <div class="btn-group ml-5">
            <input type="text" class="border mr-3 px-3" ng-model="fileTitle">
            <button class="btn btn-outline-secondary" ng-click="batchDownload('csv')">CSV导出</button>
            <button class="btn btn-outline-secondary" ng-click="batchDownload('xls')">XLS导出</button>
        </div>
    </div>

    <!--下载列表-->
    <div class="card-body layui-border mb-3">
<?php foreach ($linker as $i => $link): ?>
        <div class="d-flex align-items-center justify-content-between block-hover-shadow cp py-4px">
            <div class="layui-form">
                <input type="checkbox" name="<?= $builderID ?>DownloadRow<?= $i + 1 ?>" layui-form-render lay-filter="ym2_form_checkbox" ng-true-value="1" ng-false-value="0" ng-model="checkboxList[<?= $i ?>]">
                <text class="text-secondary f13">{{ fileTitle + "_<?= $i + 1 ?>" }}</text>
            </div>
            <div class="d-flex align-items-center f13">
                <text class="text-secondary f14 pr-5"><?= ($i + 1) >= $countLinker ? ($totalCount - $i * $limit) : $limit ?>/<?= $totalCount - $i * $limit ?></text>
                <span class="cp text-black-50 text-underline text-hover-primary" ng-click="downloadRequest(<?= $i ?>, '<?= $link ?>', 'csv')">CSV格式</span>
                <span class="f15 layui-font-gray">｜</span>
                <span class="cp text-black-50 text-underline text-hover-primary" ng-click="downloadRequest(<?= $i ?>, '<?= $link ?>', 'xls')">XLS格式</span>
            </div>
        </div>
<?php if ($i + 1 < $countLinker): ?>
        <hr class="my-0">
<?php endif; ?>
<?php endforeach; ?>
    </div>

    <!--页面结束-->
    <?= $currentBuilder->endPage() ?>
</div>
